#include <iostream>
#include <cstdlib>
#include <cstdio>

using namespace std;

int main()
{
	int p, e, i, d;
	int k = 1;
	while(scanf("%d%d%d%d", &p, &e, &i, &d) && p != -1 && e != -1 && i != -1 && d != -1)
	{
		int x = d + 1;
		while(abs(x - i) % 33 != 0) x++;
		while(1)
		{
			if(abs(x - e) % 28 == 0 && abs(x - p) % 23 == 0)
			{
					break;
			}
			else
				x += 33;
		}
		printf("Case %d: the next triple peak occurs in %d days.\n", k, x - d);
		k++;
	}
	return 0;
}
